package com.atm.servlet;

import com.atm.pojo.Manager;
import com.atm.service.AdminUserService;
import com.atm.service.impl.AdminUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class AdminLoginServlet extends HttpServlet {
    private final AdminUserService adminUserService =new AdminUserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//
        String name = req.getParameter("name");
        String password = req.getParameter("password");
//
        Manager manager = adminUserService.findManager(name, password);
        if (null==manager){
            req.setAttribute("error","用户登录失败");
            req.getRequestDispatcher("changepage/login.jsp").forward(req,resp);
        }else {
            //登录成功 跳转页面
            resp.sendRedirect("list");
//            req.getRequestDispatcher("changepage/userlist.jsp").forward(req,resp);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
